#include "StdAfx.h"
#include "BoxEditor.h"
#include "EditorHelper.h"
#include "./FunctionDrivers/FunctionDriverBox.h"

REGISTERE_EDITOR(CBoxEditor);

CBoxEditor::CBoxEditor(void)
{

}

CBoxEditor::~CBoxEditor(void)
{

}
CString CBoxEditor::GetID(void)
{
	return BOX_LWH_GUID;
}

CBoxInfo* CBoxEditor::GetShapeInfo()
{
	return &m_Info;
}
void CBoxEditor::Initialize(CAnyView* pView)
{
	m_Info.Reset();	

	AddSubEditor(new CPointCapture(m_Info.ptStart), 
		CBoxInfo::START_POINT);
	AddSubEditor(new CRectCapture(m_Info.ptStart, m_ptBottomEnd,
		m_Info.dLength,m_Info.dWidth),
		CBoxInfo::LENGTH);
	AddSubEditor(new CHeightCapture(m_ptBottomEnd, m_ptTopEnd, m_Info.dHeight),
		CBoxInfo::HEIGHT);

	CModelEditor::Initialize(pView);
}


bool CBoxEditor::CreatePreviewShape()
{
	if(CurrentStep()==CBoxInfo::START_POINT)
		return false;

	if(m_Info.dHeight<1)
		m_Info.dHeight = 1;
	if(CurrentStep() == CBoxInfo::HEIGHT)
	{
		m_ptBottomEnd.SetX(m_Info.ptStart.X() + m_Info.dLength);
		m_ptBottomEnd.SetY(m_Info.ptStart.Y() + m_Info.dWidth);
	}
	TopoDS_Shape shape;
	CBoxBuilder builder;
	if(builder.Build(&m_Info, shape))
	{
		SetPreviewShape(shape);
		return true;
	}

	return false;
}

bool CBoxEditor::CreateShapeLabel(TDF_Label& label)
{
	label = NewLabel(_T("Box"));

	m_Info.AddToLabel(label);

	Handle(CFunctionDriverBox) functionDriver;
	return ProcessFunctionDriver<CFunctionDriverBox>(label, functionDriver);
}